package com.blb.service.impl;

import com.blb.mapper.DepartmentMapper;
import com.blb.pojo.Department;
import com.blb.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentDAO;

    @Override
    public List<Department> findAll() {
        return departmentDAO.selectAll();
    }

    @Override
    public Department findById(Long id) {
        try {
            return departmentDAO.selectById(id);
        }catch (EmptyResultDataAccessException ex){
            return null;
        }
    }

    @Override
    public void saveDepartment(Department department) {
        departmentDAO.insertDepartment(department);
    }

    @Override
    public void updateDepartment(Department department) {
        departmentDAO.updateDepartment(department);
    }

    @Override
    public void deleteDepartment(Long id) {
        departmentDAO.deleteDepartment(id);
    }
}
